//class Solution {
//public:
//    vector<int> sortedSquares(vector<int>& nums) {
//        for (int i = 0; i < nums.size(); i++)
//        {
//            nums[i] = nums[i] * nums[i];
//        }
//        sort(nums.begin(), nums.end());
//        return nums;
//    }
//};
//class Solution {
//public:
//    int removeElement(vector<int>& nums, int val) {
//        int left = 0;
//        int right = 0;
//        for (int i = right; i < nums.size(); i++)
//        {
//            if (val != nums[i])
//            {
//                nums[left++] = nums[i];
//            }
//
//        }
//
//
//        return left;
//
//    }
//};
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> generateMatrix(int n) {
    int left = 0, right = n - 1, up = 0, down = n - 1;
    vector<vector<int>>ret(n,vector<int>(n,0));

    int count = 1;
    while (1)
    {
        for (int j = left; j <= right; j++)
            ret[up][j] = count++;
        if (++up > down)break;

        for (int i = up; i <= down; i++)
            ret[i][right] = count++;
        if (--right < left)break;

        for (int j = right; j >= left; j--)
            ret[down][j] = count++;
        if (--down < up)break;


        for (int i = down; i >= up; i--)
            ret[i][left] = count++;
        if (++left > right)break;

    }
    return ret;





}
int main()
{
    vector<vector<int>>ret;
    ret = generateMatrix(7);


}
class Solution {
public:

    vector<vector<int>> generateMatrix(int n) {
        int left = 0, right = n - 1, up = 0, down = n - 1;
        vector<vector<int>>ret(n, vector<int>(n, 0));

        int count = 1;
        while (1)
        {
            for (int j = left; j <= right; j++)
                ret[up][j] = count++;
            if (++up > down)break;

            for (int i = up; i <= down; i++)
                ret[i][right] = count++;
            if (--right < left)break;

            for (int j = right; j >= left; j--)
                ret[down][j] = count++;
            if (--down < up)break;


            for (int i = down; i >= up; i--)
                ret[i][left] = count++;
            if (++left > right)break;

        }
        return ret;





    }
};